﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPS.SDK.model.yunfile
{
    /// <summary>
    /// 云文件集合类
    /// </summary>
    public class FileList
    {
        public long result;
        public List<FileInfo> fileInfos;

        public static FileList fromJsonObject(JObject jsonObject)
        {
            FileList fileList = new FileList();
            fileList.fileInfos = new List<FileInfo>();
            fileList.result = Convert.ToInt64(jsonObject["result"]);

            JArray fileArray = JsonConvert.DeserializeObject<JArray>(jsonObject["files"].ToString());
            if (fileArray != null)
            {
                for (int i = 0; i < fileArray.Count; i++)
                {
                    JObject fileInfoObject = fileArray[i] as JObject;
                    FileInfo fileInfo = new FileInfo();
                    fileInfo.fname = fileInfoObject["file_name"].ToString();
                    fileInfo.fileid = fileInfoObject["open_fileid"].ToString();
                    fileInfo.ftype = fileInfoObject["file_type"].ToString();
                    fileInfo.ctime = Convert.ToInt64(fileInfoObject["ctime"]);
                    fileInfo.mtime = Convert.ToInt64(fileInfoObject["mtime"]);
                    fileList.fileInfos.Add(fileInfo);
                }
            }
            return fileList;
        }
    }
}
